Ext.define('xyc.view.PurchaseForm', {
    extend: 'Ext.Panel',
    xtype: 'purchaseform',
    config: {
        layout: 'card',
        groupByDay: true,
        loadingText: '加载中...'
    },
    initialize: function () {
        this.callParent();
        this.formpanel = new Ext.form.Panel({
            standardSubmit: false,
            items: [
                {
                    xtype: 'toolbar',
                    docked: 'top',
                    layout: { pack: 'left' },
                    items: [
                        {
                            ui: 'back',
                            text: '取消',
                            scope: this,
                            handler: function () {
                                this.getParent().setActiveItem(this.prevCard, {
                                    type: 'slide',
                                    reverse: true,
                                    scope: this,
                                    after: function () {
                                        this.destroy();
                                    }
                                });
                            }
                        },
                        { xtype: 'spacer' },
                        {
                            text: '提交',
                            scope: this,
                            handler: function () {
                                if(!(this.formpanel.getValues().hhlxbm == '402881ee43226cb201435637c4f131ea'||this.formpanel.getValues().hhlxbm == '402881ee42b153ca0142da4e563313a9')){
                                    if (!/^\d+(\.\d+)?$/.test(this.formpanel.getValues().price) ) {
                                        Ext.Msg.alert('', '无效价格', Ext.emptyFn);
                                        return;
                                    }else {
                                        if (parseFloat(this.formpanel.getValues().price) > parseFloat(this.formpanel.getValues().maxprice)) {
                                            Ext.Msg.alert('', '不能超过限价', Ext.emptyFn);
                                            return;
                                        }
                                    }
                                }
                                this.formpanel.submit({
                                    url: server+'/ext/com.cinsea.mobile.ext.XycAction?action=purchase',
                                    params: {processid: this.processid},
                                    scope: this,
                                    waitMsg: {message: '请稍候...', cls: 'demos-loading'},
                                    success: function (form, result) {
                                        this.prevCard.refresh();//reload parent store
                                        this.getParent().setActiveItem(this.prevCard, {
                                            type: 'slide',
                                            reverse: true,
                                            scope: this,
                                            after: function () {
                                                this.destroy();
                                            }
                                        });
                                    }})

                            }
                        }

                    ]
                },
                {
                    xtype: 'fieldset',
                    title: '采购申请',
                    defaults: {
                        labelAlign: 'left',
                        labelWidth: '40%'
                    },
                    items: [
                        {
                            xtype: 'textfield',
                            label: '单价',
                            name: 'price'
                        },
                        {
                            xtype: 'textfield',
                            label: '数量',
                            readOnly: true,
                            name: 'num'
                        },
                        {
                            xtype: 'textfield',
                            label: '限价',
                            readOnly:true,
                            name: 'maxprice'
                        },
                        {
                            xtype: 'textfield',
                            label: '是否采购',
                            readOnly: true,
                            name: 'caigou'
                        },
                        {
                            xtype: 'textfield',
                            label: '换花类型',
                            readOnly: true,
                            name: 'type'
                        },
                        {
                            xtype: 'textfield',
                            label: '换花备注',
                            readOnly: true,
                            name: 'hhbz'
                        } ,
                        {
                            xtype: 'textfield',
                            //label: '换花备注',
                            hidden:true,
                            name: 'hhlxbm'
                        }
                    ]
                }

            ]

        });
        this.add(this.formpanel);
    },
    setProcessid: function (processid,price,num,maxprice,caigou,type,hhbz,hhlxbm) {
        this.formpanel.setValues({
            price: price,
            num:num,
            maxprice: maxprice,
            caigou:caigou,
            type:type,
            hhbz:hhbz,
            hhlxbm:hhlxbm

        });
        this.processid = processid;

    },
    setPrevcard: function (prevc) {
        this.prevCard = prevc;
    }
});